package com.lakudouzi.flink.cdc.config;//package com.lakudouzi.flink.cdc.config;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import com.lakudouzi.flink.cdc.MysqlCdcInfo;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class ElasticsearchConfig {

    @Bean
    public ElasticsearchClient elasticsearchClient() {
        String serverUrl = "http://192.168.1.21:9200";

        RestClient client = RestClient
                .builder(HttpHost.create(serverUrl))
                .build();

//        RestClient client = RestClient.builder(new HttpHost("192.168.1.21", 9200, "http")).build();
//        RestClient client = RestClient.builder(new HttpHost(mysqlCdcInfo.getIp(), mysqlCdcInfo.getPort(), "http")).build();
        RestClientTransport restClientTransport = new RestClientTransport(client, new JacksonJsonpMapper());
        return new ElasticsearchClient(restClientTransport);
    }


}
